package com.repair.user.controller;

import com.repair.api.user.response.data.UserInfo;
import com.repair.base.result.JsonResult;
import com.repair.satoken.utils.StpKit;
import com.repair.user.pojo.dto.UserUpdateParam;
import com.repair.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 郑春雨
 * @since 2024-09-12
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "用户信息查询")
    @GetMapping("/getUserInfo")
    public JsonResult<UserInfo> getUserInfo() {
        Long userId = Long.valueOf((String) StpKit.USER.getLoginId());
        UserInfo userInfo = userService.getUserInfo(userId);
        return JsonResult.ok(userInfo);
    }

    @ApiOperation(value = "用户修改昵称")
    @PostMapping("/updateNickName")
    public JsonResult<String> updateNickName(@RequestBody UserUpdateParam userUpdateParam) {
        userService.updateNickName(userUpdateParam);
        return JsonResult.ok("修改成功");
    }

    @ApiOperation(value = "用户上传头像")
    @PostMapping(value = "/updatePhoto", consumes = "multipart/form-data")
    public JsonResult<String> updatePhoto(
            @ApiParam(value = "上传文件", required = true)
            @RequestPart(value = "file")
            MultipartFile file) {
        String profilePhotoUrl = userService.updatePhoto(file);
        return JsonResult.ok(profilePhotoUrl);
    }


}
